<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
      <!--BEGIN TITLE & BREADCRUMB PAGE-->
      <div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
          <div class="page-header pull-left">
              <div class="page-title">知识结构管理</div>
          </div>
          <ol class="breadcrumb page-breadcrumb pull-left">
              <li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li>知识库管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li class="active">知识结构管理</li>
          </ol>
           
          <div class="clearfix"></div>
      </div>
      <!--END TITLE & BREADCRUMB PAGE-->
      <!--BEGIN CONTENT-->
      <div class="page-content">
        <!-- 知识分类s -->
       
	    
        <!-- 知识分类e -->
        <div class="row">
	        <div class="col-lg-4">
	            <div class="panel" style="height: 540px; overflow: auto;">
	                <div class="panel-heading">类管理
	                	<span class="subtitle">通过本体定义知识库结构

	                	</span>
	                </div>
	                <div class="panel-heading">
	                	<span class="subtitle">
	                	
	       	<button type="button" id="savejiedian"  data-toggle="tooltip" title="新增"  class="btn btn-green btn-square"  onclick="addclass(0)" ><i class="fa fa-plus"></i></button>&nbsp;
			<button type="button" id="xiugaijiedian"  data-toggle="tooltip" title="修改"  class="btn btn-green btn-square"  onclick="addclass(1)" class="btn btn-green btn-square"><i class="fa fa-pencil-square-o"></i></button>&nbsp;
			<button type="button" id="shanchujiedian"  data-toggle="tooltip" title="删除"  class="btn btn-green btn-square"  onclick="delclass()" ><i class="glyphicon glyphicon-trash"></i></button>&nbsp;
			<!-- <button type="button" id="daorujiedian"  data-toggle="tooltip" title="导入"  class="btn btn-green btn-square"  onclick="importclass()" ><i class="glyphicon glyphicon-open"></i></button>&nbsp;
			<button type="button" id="daochujiedian"  data-toggle="tooltip" title="导出"  class="btn btn-green btn-square"  onclick="exportclass()" ><i class="glyphicon glyphicon-save"></i></button>&nbsp;
			<button type="button" id="chonggoujiedian"  data-toggle="tooltip" title="重构"  class="btn btn-green btn-square"  onclick="reconsitution()" ><i class="fa fa-refresh"></i></button> -->
				</span>
	                </div>
	                <div class="panel-body" >
	                	<ul id="tree" class="ztree" style="width:270px"; overflow:auto;"></ul>
	                	<div id="dataNull" class="panel-body" style="height: 90px; line-height: 50px;" align="center"></div>
	                </div>
	            </div>
	        </div>
	        
	        <div class="col-lg-8">
	        	<div class="panel" style="height: 260px;overflow: auto;">
	                <div class="panel-heading">数据属性管理
	                    <span class="subtitle">管理知识库基础属性，例如：机构的名称、地址等。</span>
	                     <button style="float: right;" class="btn btn-sm btn-primary" onclick="graph()">图形化展示</button>
	                     
	                </div>
	                <div id="btnd"></div>
	                	<div id="dataNull1" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
				<span class='subtitle' style="font-size: 15px;">数据为空!</span>
		   </div>
	                
	              
	            </div>
	            <div class="panel" style="height: 258px;overflow: auto;">
	                <div class="panel-heading">对象属性管理
	                    <span class="subtitle">管理知识库关联属性，例如：人物与机构的关联关系。</span>
	                </div>
	                <div id="btndclass"></div>
	                  	<div id="dataNull2" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
				<span class='subtitle' style="font-size: 15px;">数据为空!</span>
		   </div>
	                 
	                
	            </div>
	        </div>
        </div>
        
      </div>
                     
    <!--END CONTENT-->
    </div>
    
<SCRIPT type="text/javascript" >
//提示
$("#savejiedian").mouseenter(function(){
	$("[data-toggle='tooltip']").tooltip();
});
$("#xiugaijiedian").mouseenter(function(){
	$("[data-toggle='tooltip']").tooltip();
});
$("#shanchujiedian").mouseenter(function(){
	$("[data-toggle='tooltip']").tooltip();
});
$("#daorujiedian").mouseenter(function(){
	$("[data-toggle='tooltip']").tooltip();
});
$("#daochujiedian").mouseenter(function(){
	$("[data-toggle='tooltip']").tooltip();
});
$("#chonggoujiedian").mouseenter(function(){
	$("[data-toggle='tooltip']").tooltip();
});
/* --------zhongfeng--------------图形展示------------------*/
function graph() {
		layer.open({
			type : 2,
			area : [ '800px', '600px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title : "图形展示",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '关闭' ],
			content : [ "knowledge-edit-data-graph.html", 'no' ],
			yes: function(index,layer){
    	                  var iframeWin = parent.window[layer.find('iframe')[0]['name']];
    	                   iframeWin.save();
    	              },
					cancel : function(index) {
					}
				});
	};




//----------------------------------------------
	//树状结构
var parentname=1;
var sum;
	$(function() {
	parentname=1;
		get();
	});
	function getsum() {
		return sum+1;
	}
	function get() {
		initTree();
		//xianshidata();
		//xianshiclass();
	}
	var kk=0; 
	function getkk() {
		return kk;
	}
	var order; 
	function getorder() {
		return order+1;
	}
	var objectOrder; 
	function getobjectOrder() {
		return objectOrder+1;
	}
	var id;
	function getid() {
		return id;
	}
	var classid;
	function getclassid() {
		return classid;
	}
	var classname;
	function getclassname() {
		return classname;
	}
	var objectPropertyid;
	function getobjectPropertyid() {
		return objectPropertyid;
	}
	var classnameEn;
	function initTree() {
		$.ajax({
			type : "post",
			url : "./KnowledgeclassListall.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}

	function drawTree(data) {
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : false
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
			if(data.length>0){
					$("#dataNull").hide();
				}else{
					$("#dataNull").html("<span class='subtitle' style=\"font-size: 15px;\">数据为空!</span>");
				}	
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);//指定某节点折叠
		var zTreeResult = zTree.getNodes();
		sum=zTreeResult.length;
	}
	function onClick(e, treeId, treeNode) {
		classid = treeNode.id;
		classname = treeNode.name;
		classnameEn = treeNode.nameEn;
		if(typeof treeNode.children == 'undefined'){
			sum = 0;
		}else{
			sum=treeNode.children.length;
		}
		  if(treeNode.children==null)
        {
       parentname=0;
        }else{
         parentname=1;
        }
        xianshidata();
	    xianshiclass();
	}
	//对象类型
	function xianshiclass() {
		$.ajax({
					type : "post",
					url : "./KnowledgeObjectPropertyList.do",
					data : {
						"lid" : classid
					},
					dataType : "json",
					async : false,
					success : function(data) {
						var str = "";
						$("#btndclass").html("");
						str += "<div  class=\"panel-body\">";
						$("#dataNull2").hide();
						for ( var i = 0; i < data.length; i++) {
						
						str += "<button type=\"button\" class=\"btn btn-green btn-square\" style=\"margin-bottom: 10px;\"  onclick=\"createclass('"
									+ data[i].id
									+ "')\" >"
									+ data[i].name+" ["+data[i].nameen+"]"
									+ "</button>";
							str += "           ";
						}
						str += "<button type=\"button\" class=\"btn btn-green btn-square\" style=\"margin-bottom: 10px;\" onclick=\"createclass('"
								+ 0 + "')\"> + </button>";
						str += "</div>";
						$("#btndclass").append(str);
						objectOrder=data.length;
					},
					error : function(data) {
						alert("请求失败");
					}
				});

	};

	//删除对象类型
	function delObjectclass() {
	if(objectPropertyid!="0"){
	if (confirm("是否确认删除！！")) {
		$.ajax({
			type : "post",
			url : "./KnowledgeObjectPropertyydel.do",
			data : {
				"id" : objectPropertyid
			},
			dataType : "json",
			success : function(data) {
				xianshiclass();
				layer.msg("删除成功");
				
			},
			error : function(data) {
				alert("请求失败");
			}
		});
		}
		
		}
		else{
		      alert("编辑时，才能删除");
		}
	
	
	}
	//数据基本类型
	function xianshidata() {
		$.ajax({
					type : "post",
					url : "./KnowledgeDataPropertyList.do",
					data : {
						"lid" : classid
					},
					dataType : "json",
					async : false,
					success : function(data) {
						var str = "";
						$("#btnd").html("");
						$("#dataNull1").hide();
						str += "<div  class=\"panel-body\">";
						for ( var i = 0; i < data.length; i++) {
							str += "<button type=\"button\" class=\"btn btn-blue btn-square\" style=\"margin-bottom: 10px;\"  onclick=\"create('"
									+ data[i].id
									+ "')\" >"
									+ data[i].name+" ["+data[i].nameen+"]"
									+ "</button>";
							//str += "<button type=\"button\" class=\"btn btn-blue btn-square\" style=\"margin-bottom: 10px;\"  onclick=\"del('"
								//	+ data[i].id
								//	+ "')\"  >"
								//	+ "删除"
								//	+ "</button>";
							str += "           ";
						}
						str += "<button type=\"button\" class=\"btn btn-blue btn-square\" style=\"margin-bottom: 10px;\"   onclick=\"create('"
								+ 0 + "')\"> + </button>";
						str += "</div>";
						$("#btnd").append(str);
						order=data.length;
					},
					error : function(data) {
						alert("请求失败");
					}
				});

	};
	//删除数据类型
	function del() {
	if(id!="0")
	{
	if (confirm("是否确认删除！！")) {
	
		$.ajax({
			type : "post",
			url : "./KnowledgeDataPropertydel.do",
			data : {
				"id" : id
			},
			dataType : "json",
			success : function(data) {
				xianshidata();
				layer.msg("删除成功");
			},
			error : function(data) {
				alert("请求失败");
			}
		});
		}
		
		}
		else{
		      alert("编辑时，才能删除");
		}

	}

	//数据类型加载表单；
	function createclass(lid) {
		objectPropertyid = lid;
		layer.open({
			type : 2,
			area : [ '1050px', '630px' ],
			scrollbar : false,
			shadeClose : true,
			move : false,
			fix : false, //不固定
			title:"关联字段编辑",
			btn : [ '保存 ', '删除', '关闭' ],
			content : "knowledge-DataProperty-class-from.html",
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save("0");
			},btn2: function(index, layer) {
				delObjectclass();
			},
			cancel : function(index) {
			}
		});
	}
	
	//数据类型加载表单；
	
	function create(lid) {
		id = lid;
		layer.open({
			type : 2,
			area : [ '1050px', '630px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title:"基础字段编辑",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '删除', '关闭' ],
			content : "knowledge-DataProperty-data-from.html",
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save("0");
			},
			btn2: function(index, layer) {
				del();
			},
			cancel : function(index) {
			}
		});
	}
	//新建class的页面；


	
	function addclass(lid) {
		kk = lid;
		if(classid!=null||kk==0){
			layer.open({
				type : 2,
				area : [ '1050px', '630px' ],
				fix : false, //不固定
				scrollbar : false,
				shadeClose : true,
				move : false,
				title:"添加或编辑类",
				skin : 'layui-layer-rim', //加上边框
				btn : [ '保存 ', '关闭' ],
				//zIndex: layer.zIndex,
				content : ["knowledge-Classes-class-from.html", 'no'],
				yes : function(index, layer) {
					var iframeWin = parent.window[layer.find('iframe')[0]['name']];
					iframeWin.Page();
					   
				},
				cancel : function(index) {
				}
			});
		}else{
			alert("请选中类");
		}
		
	};

	function redis() {
		$.ajax({
			type : "post",
			url : "./Knowledgeredis.do",
			data : {},
			dataType : "json",
			success : function(data) {
				get();
				layer.msg("发布成功");

			},
			error : function(data) {
				alert("请求失败");
			}
		});
	};
	function delclass() {
		if(classid != null && classid != ''){
			if (parentname == 0) {
				if (confirm("是否确认删除！！")) {
					$.ajax({
						type : "post",
						url : "./KnowledgeClassesclassdel.do",
						data : {
							"id" : classid
						},
						dataType : "json",
						success : function(data) {
							if(data.result == 0 ){
								get();
								$("#btnd").html("");
								$("#dataNull1").show();
								$("#btndclass").html("");
								$("#dataNull2").show();
								layer.msg("删除成功");
								classname="";
							}else{
								layer.msg("删除失败！有关联无法删除！请先删除产品管理和权重配置以及大数据仓储关联！");
							}
							
						},
						error : function(data) {
							alert("请求失败");
						}
					});
				}
			} else {
				alert("有子分类不允许删除！");
			}
		} else {
				alert("请选择要删除的类！");
			}
	};
	//导出
	function exportclass(){
	/* if (confirm("是否确认导出！！")) {
		/* $("#generalWordCategoryId").val(GWordCategoryId);
		document.forms['aa'].submit(); 
		var _downiframe = $("iframe#_downiframe");
		if (_downiframe.length == 0) {
			_downiframe =$("<iframe id='_downiframe' name='_downiframe' style='display:none'></iframe>").appendTo($("body"));
		}
		_downiframe.attr("src", "classExportdownload.do");
	} */
		layer.open({
			type : 2,
			area : [ '450px', '350px' ],
			scrollbar : false,
			shadeClose : true,
			fix : false, //不固定
			title : '导出知识库结构',
			//maxmin : true,  
			skin : 'layui-layer-rim', //加上边框
			btn : [ '导出','关闭'],
			content : [ "knowledge-Classes-class-export.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.start();
			},cancel : function(index) {
			}
		});
	
	
}

//导入
function importclass() {
		layer.open({
			type : 2,
			area : [ '800px', '600px' ],
			scrollbar : false,
			shadeClose : true,
			fix : false, //不固定
			title : '普通词表导入',
			//maxmin : true,  
			skin : 'layui-layer-rim', //加上边框
			btn : [ '导入','关闭'],
			content : [ "knowledge_DataProperty_class_import.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.start();
			},cancel : function(index) {
			}
		});
	}
	
	//重构
	function reconsitution(){
		if (confirm("您是否确定已手动删除关系数据库表？")) {
		$.ajax({
			type : "post",
			url : "reconsitution.do",
			data : {
				"classnameEn" : classnameEn
			},
			dataType : "json",
			success : function(data) {
				xianshiclass();
				if(data == 'yes'){
					layer.msg("重构成功！");
				}else{
					layer.msg("重构失败！");
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
		}
	}
</SCRIPT>    
    
  
<?} ?>
  
